﻿using JamesZhao.Engine.Graphics.Effects;
using JamesZhao.Engine.Graphics.Surfaces;
using JamesZhao.Engine.Graphics.Visuals;
using SlimDX.DXGI;

namespace JamesZhao.Engine.Graphics.RenderStages.Old
{
    internal class WriteNormalToRtStage : RenderStage
    {
        public WriteNormalToRtStage(GraphicsDevice device)
        {
            NormalEffect = new GpuProgram(device, "Shaders/WriteNormalToRt.fx");
        }

        public ColorSurface Output { get; set; }

        public GpuProgram NormalEffect { get; set; }

        public override string Name
        {
            get { return "Write Normal"; }
        }

        protected override void OnRender(GraphicsDevice device, SwapChain swapChain, VisualsList visualsList,
                                         Camera camera)
        {
            device.ImmediateContext.OutputMerger.SetTargets(Output.TargetView);

            foreach (Drawable renderable in visualsList.Drawables)
            {
                renderable.RenderWithGpuProgram(device, camera, NormalEffect);
            }
        }
    }
}